package k4_thread.demo03;

public class SaleTicketByRunnable implements Runnable {
    //初始化一共有100张票,因为车票是所有火车站共享的，必须使用static进行修饰
    private static int totalTickets = 100;

    @Override
    public void run() {
        while(totalTickets>0){
            try {
                System.out.println(Thread.currentThread().getName()+"卖了一张票，剩余"+ --totalTickets+"张票");
                Thread.sleep(200);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}

class Test1{
    public static void main(String[] args) {

        new Thread(new SaleTicketByRunnable(),"南京").start();
        new Thread(new SaleTicketByRunnable(),"广州").start();
        new Thread(new SaleTicketByRunnable(),"南宁").start();

    }
}
